#ifndef DEVICEBUTTON_H
#define DEVICEBUTTON_H

#include <qwidget.h>

class Devicebutton:public QWidget
{

    Q_OBJECT
    Q_ENUMS(ButtonStyle)
    Q_ENUMS(ButtonColor)

    Q_PROPERTY(bool canMove READ getCanMove WRITE setCanMove)
    Q_PROPERTY(QString text READ getText WRITE setText)

    Q_PROPERTY(QString colorNormal READ getColorNormal WRITE setColorNormal)
    Q_PROPERTY(QString colorAlarm READ getColorAlarm WRITE setColorAlarm)

    Q_PROPERTY(ButtonStyle buttonStyle READ getButtonStyle WRITE setButtonStyle)
    Q_PROPERTY(ButtonColor buttonColor READ getButtonColor WRITE setButtonColor)

public:
    //按钮样式
    enum ButtonStyle
    {
        ButtonStyle_Circle=0,   //圆形
        ButtonStyle_Police=1,   //警察
        ButtonStyle_Bubble=2,   //气泡
        ButtonStyle_Bubble2=3,  //气泡2
        ButtonStyle_Msg=4,      //消息
        ButtonStyle_Msg2=5,     //消息2
    };

    //设备按钮颜色
    enum ButtonColor
    {
        ButtonColor_Green=0,
        ButtonColor_Blue=1,
        ButtonColor_Red=2,
        ButtonColor_Gray=3,
        ButtonColor_Black=4,
        ButtonColor_Purple=5,
        ButtonColor_Yellow=6
    };

public:
    explicit Devicebutton(QWidget *parent=0);
    ~Devicebutton();

protected:
    void paintEvent(QPaintEvent *);
    bool eventFilter(QObject *watched, QEvent *event);

private:
    bool canMove;           //是否可移动
    QString text;           //显示文字

    QString colorNormal;    //正常颜色
    QString colorAlarm;     //报警颜色

    ButtonStyle buttonStyle;    //按钮样式
    ButtonColor buttonColor;    //按钮颜色

    bool isPressed;             //数据是否按下
    QPoint lastPoint;           //鼠标按下最后坐标

    QString type;               //图片末尾类型
    QString imgPath;            //背景图片路径
    QString imgName;            //背景图片明朝

    bool isDark;            //是否加深报警
    QTimer *timer;

private slots:
    void checkAlarm();              //切换报警状态

public:
    bool getCanMove() const;
    QString getText() const;

    QString getColorNormal() const;
    QString getColorAlarm() const;

    ButtonStyle getButtonStyle() const;
    ButtonColor getButtonColor() const;

    QSize sinHint() const;
    QSize minimumSizeHint() const;

public Q_SLOTS:
    void setCanMove(bool canMove);          //设置可移动
    void setText(const QString &text);      //设置显示文字

    void setColorNormal(const QString &colorNormal);
    void setColorAlarm(const QString &colorAlarm);

    void setButtonStyle(const ButtonStyle &buttonStyle);        //设置样式
    void setButtonColor(const ButtonColor &buttonColor);        //设置颜色

Q_SIGNALS:
    void clicked();
    void doubleClicked();
};

#endif // DEVICEBUTTON_H
